/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.zumbits.avd.server;

import br.com.zumbits.avd.logger.Log;
import br.com.zumbits.avd.comunication.protocol.ReceiveProcess;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author zumbits
 */
public class HttpsServlet extends HttpServlet {

    private HttpServletRequest request;
    private HttpServletResponse response;
    private PrintWriter out;
    private ReceiveProcess receiveProcess;

    public HttpsServlet() {
        receiveProcess = new ReceiveProcess();
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) {
        try {
            this.request = request;
            this.response = response;
            this.response.setContentType("text/xml");
            this.out = this.response.getWriter();

            Object xmlSend = receiveProcess.receive(request, response);

            if (xmlSend != null) {
                out.print(xmlSend);
            } else {
                //XML inválido
                Log.print("error", "xml inválido " + xmlSend);
            }
        } catch (Exception ex) {
            //XML inválido
            out.print(ex.getMessage());
            Log.print("error", "exception\n" + ex.getMessage());
        }
    }
}
